package com.saver.core.processor;

import java.util.List;
import java.util.TreeMap;

import android.util.Log;

import com.saver.core.domain.Banco;
import com.saver.core.processor.comparator.IntegerComparator;
import com.saver.core.processor.comparator.StringComparator;

public class ProcessSMSFactory {

	private static final String TAG = "ProcessSMSFactory";
	
	private TreeMap<Integer, ProcessorSMS> listProcess;
	private TreeMap<String, Banco> listBancos;
	
	public ProcessSMSFactory(List<Banco> bancos) {
		listProcess = new TreeMap<Integer, ProcessorSMS>(new IntegerComparator());
		listBancos = new TreeMap<String, Banco>(new StringComparator());
		
		for (Banco banco : bancos) {
			String numero = banco.getNumero();
			Log.d(TAG, "numero: " + numero + " - banco: " + banco.getNombre());
			listBancos.put(numero, banco);
		}
		
		addItem (new BBVA());
		addItem (new Scotiabank());
		addItem (new BCP());
		addItem (new Interbank());
	}
	
	private void addItem (ProcessorSMS processorSMS) {
		listProcess.put(processorSMS.tipoBanco().getId(), processorSMS);
	}
	
	public ProcessorSMS getProcessSMS (String number) {
		Banco banco = listBancos.get(number);
		ProcessorSMS processorSMS = null;
		if (banco != null) {
			processorSMS = listProcess.get(banco.getId());
		}
		return processorSMS;
	}
}
